<div class="row">
    <div class="col-xs-12">
        <div class="box-body" style="display: block;">

            <form method="GET" action="{{url('admin/wiki/editWiki')}}" class="form-horizontal" accept-charset="UTF-8" pjax-container="1">

                <div class="box-body fields-group">

                    <div class="form-group">
                        <label for="logo" class="col-sm-2 control-label">封面图：</label>
                        <div class="col-sm-2">
                            <input id="logo_upload" width="50px;" height="50px;" type="file" class="file-loading"
                                   data-src="{{isset($wikiInfo["cover_img"]) ? $wikiInfo["cover_img"] : ""}}">
                            <input id="logo" type="hidden" name="cover_img"
                                   value="{{isset($wikiInfo["cover_img_id"]) ? $wikiInfo["cover_img_id"] : "c027f30rs0rs00000ovyi13"}}">
                        </div>
                    </div>


                    <div class="form-group  ">
                        <label for="text" class="col-sm-2 control-label">wiki名称</label>
                        <div class="col-sm-5">
                            <div class="input-group">
                                <input type="hidden" id="text" name="wiki_id" value="{{$wikiInfo['id']}}" class="form-control text" placeholder="Input Text" />
                                <input type="hidden" id="text" name="is_edit" value="1" class="form-control text" placeholder="Input Text" />
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" id="text" name="title" value="{{$wikiInfo['title']}}" class="form-control text" placeholder="Input Text" />
                            </div>
                        </div>
                    </div>

                    <div class="form-group  ">
                        <label for="currency" class="col-sm-2 control-label">价格区间</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <span class="input-group-addon">$</span>
                                <input style="width: 120px" type="text" id="currency" name="min_price" value="{{$wikiInfo['min_price']}}" class="form-control currency" placeholder="Input Currency" />
                                <input style="width: 120px" type="text" id="currency" name="max_price" value="{{$wikiInfo['max_price']}}" class="form-control currency" placeholder="Input Currency" />
                            </div>
                        </div>
                    </div>

                    <div class="form-group  ">
                        <label for="text" class="col-sm-2 control-label">系列名</label>
                        <div class="col-sm-5">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" id="text" name="series" value="{{$wikiInfo['series']}}" class="form-control text" placeholder="" />
                            </div>
                        </div>
                    </div>

                    <div class="form-group  ">
                        <label for="text" class="col-sm-2 control-label">品牌名</label>
                        <div class="input-group" style="width: 250px;">
                            <select class="form-control name" style="width: 100%;" name="brand_id"  >
                                <option @if($wikiInfo['brand'])  value="{{$wikiInfo['brand']['id']}}"  selected @endif> @if($wikiInfo['brand']) {{$wikiInfo['brand']['brand_name']}} @endif</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group  ">
                        <label for="text" class="col-sm-2 control-label">末级类目</label>
                        <div class="col-sm-5">
                            {{$wikiInfo['category_tree']}}
                            <div class="input-group" style="width: 250px;">
                                <select class="form-control category_name" style="width: 100%;" name="last_category_id"  >
                                    @foreach($lastStageCates as $cate_id => $cate_name)
                                        <option value="{{$cate_id}}"  @if($cate_id == $wikiInfo['last_category_id'])  selected @endif  > {{$cate_name}} </option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="logo" class="col-sm-2 control-label">封面图：</label>

                        @foreach($wikiInfo['imgs'] as $img)
                            <div class="col-sm-2">
                                <input  width="50px;" height="50px;" type="file" class="file-loading goods_imgs"
                                        data-src="{{isset($img["img_url"]) ? $img["img_url"] : ""}}">
                                <input  type="hidden" name="imgs[]"
                                        value="{{isset($img["img_id"]) ? $img["img_id"] : ""}}">
                                <button class="btn btn-primary delImg" >删除</button>
                            </div>
                        @endforeach

                        <button onclick="return false" class="btn btn-primary addImg" >添加</button>
                    </div>

                    <div class="form-group">
                        <label for="logo" class="col-sm-2 control-label">风格：</label>
                        <div class="col-sm-2">
                            <input type="text" id="tags" name="tags" value="{{$wikiInfo['tags']}}" class="form-control text" placeholder="" />
                            <div class="input-group" style="width: 250px;">
                                <select class="form-control tags" style="width: 100%;"   >

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-2">
                            <input class="btn btn-primary" type="submit" />
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".name").select2({
            allowClear: true,
            ajax: {
                url:"{{url('admin/wiki/searchBrand')}}",
                type: "GET",
                dataType: "json",
                delay: 250,
                data : function (params) {
                    return {
                        key: params.term
                    }
                },
                processResults: function (data, params) {
                    return {
                        results : data
                    };
                },
                mininumInputLength: 1
            }
        });
        $(".category_name").select2({
            allowClear: true
        });

        $(".tags").select2({
            allowClear: true,
            ajax: {
                url:"{{url('admin/wiki/searchStyle')}}",
                type: "GET",
                dataType: "json",
                delay: 250,
                data : function (params) {
                    return {
                        key: params.term
                    }
                },
                processResults: function (data, params) {
                    return {
                        results : data
                    };
                },
                mininumInputLength: 1
            }

        });
        $("#logo_upload").fileinput({
            language: "zh",
            overwriteInitial: true,
            showClose: false,
            showCaption: false,
            showBrowse: false,
            showRemove: false,
            showUpload: false,
            browseOnZoneClick: true,
            defaultPreviewContent: '<img src="' + $("#logo_upload").attr('data-src') + '" alt="banner" style="width:160px">',
            allowedFileExtensions: ["jpg", "png", "gif"],
            uploadUrl: "{{url('admin/extend/img/uploadtosso')}}"
        });
        $("#logo_upload").on("fileuploaded", function (event, data, previewId, index) {
            if (data.response.code == 1) {
                $("#logo").val(data.response.data.picId);
            }
        });

        function initImgs() {
            $(".goods_imgs").each(function () {
                $(this).fileinput({
                    language: "zh",
                    overwriteInitial: true,
                    showClose: false,
                    showCaption: false,
                    showBrowse: false,
                    showRemove: false,
                    showUpload: false,
                    browseOnZoneClick: true,
                    defaultPreviewContent: '<img src="' + $(this).attr('data-src') + '" alt="banner" style="width:160px">',
                    allowedFileExtensions: ["jpg", "png", "gif"],
                    uploadUrl: "{{url('admin/extend/img/uploadtosso')}}"
                });


                $(this).on("fileuploaded", function (event, data, previewId, index) {
                    if (data.response.code == 1) {
                        $(this).next("input[name='imgs[]']").val(data.response.data.picId);
                    }
                });
            });

            $(".delImg").click(function () {
                $(this).parent("div.col-sm-2").remove();
            });
        }

        initImgs();

        $(".addImg").click(function () {

            $(this).before("<div class=\"col-sm-2\">" +
                "<input  width=\"50px;\" height=\"50px;\" type=\"file\" class=\"file-loading goods_imgs\" data-src=\"\">" +
                "<input  type=\"hidden\" name=\"imgs[]\" value=\"\">" +
                "<button class=\"btn btn-primary delImg\" >删除</button></div>");

            initImgs();

        });


        $(".tags").change(function () {
           var $style = $(this).val();
           var $val = $("#tags").val();

           $("#tags").val($val + " " + $style);

        })

    })
</script>

